/*
 * BackgroundLayer.h
 *
 *  Created on: 2010-9-4
 *      Author: try
 */

#ifndef BACKGROUNDLAYER_H_
#define BACKGROUNDLAYER_H_

#include "../../commons.h"
#include "../../gdiplus/gdraw.h"

namespace S {
  class WorkPage;
  class BackgroundLayer: public Ed::Layer {
    public:
      BackgroundLayer(WorkPage* page) :
        Ed::Layer(page), background() {
        addElement(&background);
        background.createPath();
      }
      virtual ~BackgroundLayer() {

      }

    private:
      /**
       * 背景元素
       */
      class Background: public Ed::Element {
        public:
          Background() :
            bgCachedBmp(NULL) {
            bgImage = new Gdiplus::Bitmap(L"res\\Penguins.jpg");
          }
          virtual ~Background() {
            delete bgImage;
          }

          /**
           * 构建路径
           */
          void createPath(){
            setWidth(1001);
            setHeight(601);
            createBoundRect();
          }

          /**
           * 画此元素
           */
          void draw(Gdiplus::Graphics* g) {
            Gdiplus::CachedBitmap cachedBmp(bgImage, g);
            g->DrawCachedBitmap(&cachedBmp, (int)x(), (int)y());
            setModified(false);
          }
        private:
          Gdiplus::Bitmap* bgImage;
          Gdiplus::CachedBitmap* bgCachedBmp;
      };

      //背景元素
      Background background;
    };
  }
#endif /* BACKGROUNDLAYER_H_ */
